package logic

import (
	"context"
	"fmt"
	"useryk/model/mysql"
	"useryk/userrpc/internal/svc"
	"useryk/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CategorieAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCategorieAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CategorieAddLogic {
	return &CategorieAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CategorieAddLogic) CategorieAdd(in *userrpc.CategorieAddRequest) (*userrpc.CategorieAddResponse, error) {
	// todo: add your logic here and delete this line

	categorie := mysql.Categorie{
		Categoriename:  in.Categoriename,
		Categorieimage: in.Categorieimage,
		Keyword:        in.Keyword,
		Describe:       in.Describe,
		Userid:         in.Userid,
	}
	err := mysql.DB.Create(&categorie).Error
	if err != nil {
		return nil, fmt.Errorf("分类添加失败")
	}

	return &userrpc.CategorieAddResponse{
		Categorieid: int64(categorie.ID),
	}, nil
}
